set -e
set -o pipefail
if [ -z "${LOCATION}" ]; then LOCATION=""; fi
if [ -z "${EXTENSION}" ]; then EXTENSION=".xz"; fi

case "${EXTENSION}" in ".bz2") COMPRESSION_OPT="j";; ".xz") COMPRESSION_OPT="J";; esac

fixedDeflectionSensitivityNmPerV=$DEFL_SENS; fixedSpringConstantNPerM=$K; for d in $DIRS; do p=$(dirname ${d}); b=$(basename ${d})${fixedDeflectionSensitivityNmPerV//*/_${fixedDeflectionSensitivityNmPerV}}${fixedSpringConstantNPerM//*/_${fixedSpringConstantNPerM}}; mkdir -p ${p}/analysis && cd ${p}/analysis && mkdir -p ${p/\/home\/$(whoami)\/work\/curves/\/mnt\/${LOCATION}\/Users}/analysis/ && if [ -d "${b}_analysis" ]; then if [ -f "${b}_analysis.tar${EXTENSION}" ]; then tar -u${COMPRESSION_OPT}f ${b}_analysis${EXTENSION} ${b}_analysis; else tar -c${COMPRESSION_OPT}f ${b}_analysis.tar${EXTENSION} ${b}_analysis; fi && cp ${b}_analysis.tar${EXTENSION} ${p/\/home\/$(whoami)\/work\/curves/\/mnt\/${LOCATION}\/Users}/analysis/ && rm -fr ${p}/analysis/${b}_analysis; fi; done
